package com.haidong.component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AdminIndexFrame extends JFrame {
    public AdminIndexFrame(String title,Integer userId,String userName) throws HeadlessException {
        super(title);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        setLayout(new BorderLayout());

        //上面放一些用户个人信息,左边放几个按钮切换模块,剩下的放内容
        JPanel up = new JPanel();
        JLabel label = new JLabel("欢迎使用单位房产管理系统,欢迎管理员" + userName + ",您的id编号是" + userId);
        up.add(label);

        //左边放几个大按钮,用来切换右下角的内容
        JPanel left = new JPanel(new GridLayout(5,1));
        JButton system = new JButton("系统管理");
        JButton house = new JButton("房子管理");
        JButton worker = new JButton("员工管理");
        JButton dept = new JButton("物业费用");
        JButton help = new JButton("帮助");
        left.add(system);
        left.add(house);
        left.add(worker);
        left.add(dept);
        left.add(help);

        //右下卡片布局,封装了5个卡片,由左侧按钮控制
        CardLayout cardLayout = new CardLayout();
        JPanel center = new JPanel(cardLayout);

        //系统管理界面,主要负责增加删除管理员,普通用户,和修改密码
        JPanel card1 = new JPanel(new BorderLayout());
        JPanel bts = new JPanel(new GridLayout(1,4));
        CardLayout cardLayout1 = new CardLayout();
        JPanel centerDetail = new JPanel(cardLayout1);
        JButton bt1 = new JButton("增加管理员");
        JButton bt2 = new JButton("增加普通用户");
        JButton bt3 = new JButton("删除管理员/用户");
        JButton bt4 = new JButton("更改当前账户密码");
        JPanel addUser = MyUserPanel.addUser();
        JPanel addAdmin = MyUserPanel.addAdmin();
        JPanel deleteUser = MyUserPanel.deleteUser();
        JPanel updateUser = MyUserPanel.updateUser(userId);
        centerDetail.add("增加管理员",addAdmin);
        centerDetail.add("增加普通用户",addUser);
        centerDetail.add("删除管理员/用户",deleteUser);
        centerDetail.add("更改当前账户密码",updateUser);
        ActionListener systemListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "增加管理员":
                        cardLayout1.show(centerDetail,"增加管理员");
                        break;
                    case "增加普通用户":
                        cardLayout1.show(centerDetail,"增加普通用户");
                        break;
                    case "删除管理员/用户":
                        cardLayout1.show(centerDetail,"删除管理员/用户");
                        break;
                    case "更改当前账户密码":
                        cardLayout1.show(centerDetail,"更改当前账户密码");
                        break;
                }
            }
        };
        bt1.addActionListener(systemListener);
        bt2.addActionListener(systemListener);
        bt3.addActionListener(systemListener);
        bt4.addActionListener(systemListener);
        bts.add(bt1);
        bts.add(bt2);
        bts.add(bt3);
        bts.add(bt4);
        card1.add(bts,BorderLayout.NORTH);
        card1.add(centerDetail,BorderLayout.CENTER);

        //房子管理界面,默认显示查找房子信息,显示所有的房子信息
        JPanel card2 = new JPanel(new BorderLayout());
        JPanel bts2 = new JPanel(new GridLayout(1,4));
        CardLayout cardLayout2 = new CardLayout();
        JPanel centerDetail2 = new JPanel(cardLayout2);
        JPanel selectHouse = MyHousePanel.select();
        JPanel addHouse = MyHousePanel.add();
        JPanel delHouse = MyHousePanel.del();
        JPanel updateHouse = MyHousePanel.update();
        centerDetail2.add("查找房子",selectHouse);
        centerDetail2.add("增加房子",addHouse);
        centerDetail2.add("删除房子",delHouse);
        centerDetail2.add("更新房子内容",updateHouse);
        ActionListener houseListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "查找房子":
                        cardLayout2.show(centerDetail2,"查找房子");
                        break;
                    case "增加房子":
                        cardLayout2.show(centerDetail2,"增加房子");
                        break;
                    case "删除房子":
                        cardLayout2.show(centerDetail2,"删除房子");
                        break;
                    case "更新房子内容":
                        cardLayout2.show(centerDetail2,"更新房子内容");
                        break;
                }
            }
        };
        JButton bt5 = new JButton("查找房子");
        JButton bt6 = new JButton("增加房子");
        JButton bt7 = new JButton("删除房子");
        JButton bt8 = new JButton("更新房子内容");
        bt5.addActionListener(houseListener);
        bt6.addActionListener(houseListener);
        bt7.addActionListener(houseListener);
        bt8.addActionListener(houseListener);
        bts2.add(bt5);
        bts2.add(bt6);
        bts2.add(bt7);
        bts2.add(bt8);
        card2.add(bts2,BorderLayout.NORTH);
        card2.add(centerDetail2,BorderLayout.CENTER);

        //员工管理界面
        JPanel card3 = new JPanel(new BorderLayout());
        JPanel bts3 = new JPanel(new GridLayout(1,4));
        CardLayout cardLayout3 = new CardLayout();
        JPanel centerDetail3 = new JPanel(cardLayout3);
        JPanel selectWorker = MyWorkerPanel.select();
        JPanel addWorker = MyWorkerPanel.add();
        JPanel delWorker = MyWorkerPanel.del();
        JPanel updateWorker = MyWorkerPanel.update();
        centerDetail3.add("查找员工",selectWorker);
        centerDetail3.add("增加员工",addWorker);
        centerDetail3.add("删除员工",delWorker);
        centerDetail3.add("修改员工信息",updateWorker);
        ActionListener workerListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "查找员工":
                        cardLayout3.show(centerDetail3,"查找员工");
                        break;
                    case "增加员工":
                        cardLayout3.show(centerDetail3,"增加员工");
                        break;
                    case "删除员工":
                        cardLayout3.show(centerDetail3,"删除员工");
                        break;
                    case "修改员工信息":
                        cardLayout3.show(centerDetail3,"修改员工信息");
                        break;
                }
            }
        };
        JButton bt9 = new JButton("查找员工");
        JButton bt10 = new JButton("增加员工");
        JButton bt11 = new JButton("删除员工");
        JButton bt12 = new JButton("修改员工信息");
        bt9.addActionListener(workerListener);
        bt10.addActionListener(workerListener);
        bt11.addActionListener(workerListener);
        bt12.addActionListener(workerListener);
        bts3.add(bt9);
        bts3.add(bt10);
        bts3.add(bt11);
        bts3.add(bt12);
        card3.add(bts3,BorderLayout.NORTH);
        card3.add(centerDetail3,BorderLayout.CENTER);

        //物业费管理界面,完成本月计费(默认显示全部的,显示收费标准),历史计费,收费标准修改
        JPanel card4 = new JPanel(new BorderLayout());
        JPanel bts4 = new JPanel(new GridLayout(1,3));
        CardLayout cardLayout4 = new CardLayout();
        JPanel centerDetail4 = new JPanel(cardLayout4);
        //这里的二级页面还没写,等写好了再替换
        JPanel cost = CostPanel.select();
        JPanel history = CostPanel.history();
        JPanel updatePrice = CostPanel.update();
        centerDetail4.add("物业费及收费标准",cost);
        centerDetail4.add("历史物业费查询",history);
        centerDetail4.add("修改收费标准",updatePrice);
        ActionListener costListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "物业费及收费标准":
                        cardLayout4.show(centerDetail4,"物业费及收费标准");
                        break;
                    case "历史物业费查询":
                        cardLayout4.show(centerDetail4,"历史物业费查询");
                        break;
                    case "修改收费标准":
                        cardLayout4.show(centerDetail4,"修改收费标准");
                        break;
                }
            }
        };
        JButton bt13 = new JButton("物业费及收费标准");
        JButton bt14 = new JButton("历史物业费查询");
        JButton bt15 = new JButton("修改收费标准");
        bt13.addActionListener(costListener);
        bt14.addActionListener(costListener);
        bt15.addActionListener(costListener);
        bts4.add(bt13);
        bts4.add(bt14);
        bts4.add(bt15);
        card4.add(bts4,BorderLayout.NORTH);
        card4.add(centerDetail4,BorderLayout.CENTER);

        //帮助界面
        JPanel card5 = new HelpPanel();

        //监听大按钮切换页面
        ActionListener listener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
                switch (command){
                    case "系统管理":
                        cardLayout.show(center,"系统管理");
                        break;
                    case "房子管理":
                        cardLayout.show(center,"房子管理");
                        break;
                    case "员工管理":
                        cardLayout.show(center,"员工管理");
                        break;
                    case "物业费用":
                        cardLayout.show(center,"物业费用");
                        break;
                    case "帮助":
                        cardLayout.show(center,"帮助");
                        break;
                }
            }
        };

        //卡片导入主panel
        center.add("系统管理",card1);
        center.add("房子管理",card2);
        center.add("员工管理",card3);
        center.add("物业费用",card4);
        center.add("帮助",card5);

        //给左侧按钮加监听器
        system.addActionListener(listener);
        house.addActionListener(listener);
        worker.addActionListener(listener);
        dept.addActionListener(listener);
        help.addActionListener(listener);

        add(up,BorderLayout.NORTH);
        add(left,BorderLayout.WEST);
        add(center,BorderLayout.CENTER);

        setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
        setVisible(true);
    }

    public static void main(String[] args) {
        new AdminIndexFrame("测试管理员窗口",1,"root");
    }
}
